#include <stdio.h>

int main() {
    int T, n;
    scanf("%d", &T);  

    while (T--) {
        scanf("%d", &n);  
        int jz[n][n];
        int a = 1;  

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                scanf("%d", &jz[i][j]);
               if (i > j && jz[i][j] != 0) {
                    a = 0;
                }
            }
        }

        if (a) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}
